home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / rpg / crossfir.92 / crossfir / crossfire-0.92.5 / server / c_wiz.c < prev    next >
C/C++ Source or Header  |  1996-07-24  |  20KB  |  698 lines

  1. /*
  2.  * static char *rcsid_c_wiz_c =
  3.  *   "$Id: c_wiz.c,v 1.12 1996/03/06 06:37:18 master Exp $";
  4.  */
  5. /*
  6.     CrossFire, A Multiplayer game for X-windows
  7.  
  8.     Copryight (C) 1994 Mark Wedel
  9.     Copyright (C) 1992 Frank Tore Johansen
  10.  
  11.     This program is free software; you can redistribute it and/or modify
  12.     it under the terms of the GNU General Public License as published by
  13.     the Free Software Foundation; either version 2 of the License, or
  14.     (at your option) any later version.
  15.  
  16.     This program is distributed in the hope that it will be useful,
  17.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.     GNU General Public License for more details.
  20.  
  21.     You should have received a copy of the GNU General Public License
  22.     along with this program; if not, write to the Free Software
  23.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  
  25.     The author can be reached via e-mail to master@rahul.net
  26. */
  27.  
  28. /*
  29.  * End of non-DM commands.  DM-only commands below.
  30.  * (This includes commands directly from socket)
  31.  */
  32.  
  33. /* Some commands not accepted from socket */
  34.  
  35. #include <global.h>
  36. #ifndef __CEXTRACT__
  37. #include <sproto.h>
  38. #endif
  39. #include <version.h>
  40. #include <main.h>
  41. #include <spells.h>
  42. #include <treasure.h>
  43.  
  44. int command_goto (object *op, char *params)
  45. {
  46.       char *name;
  47.       object *dummy;
  48.  
  49.   if (!op)
  50.     return 0;
  51.  
  52.   if(params == NULL) {
  53.         new_draw_info(NDI_UNIQUE, 0,op,"Go to what level?");
  54.         return 1;
  55.       }
  56.   name = params;
  57.       dummy=get_object();
  58.       dummy->map = op->map;
  59.       EXIT_PATH(dummy) = add_string (name);
  60.       enter_exit(op,dummy);
  61.       free_object(dummy);
  62.       if(op->contr->loading == NULL) {
  63.     new_draw_info_format(NDI_UNIQUE, 0, op,
  64.         "Difficulty: %d.",op->map->difficulty);
  65.         /*
  66.          * Now, if we entered a new, unloaded map, set the cheat-flag in
  67.          * all objects here.
  68.          */
  69. #ifdef SET_WIZCHEAT
  70.         if(op->map != prev && !m) {
  71.           object *tmp;
  72.           for(tmp = objects; tmp != NULL; tmp = tmp->next)
  73.             if(tmp->map == op->map)
  74.               SET_WAS_WIZ(tmp);
  75.         }
  76. #endif
  77.       }
  78.       return 1;
  79.     }
  80.  
  81. /* is this function called from somewhere ? -Tero */
  82. int command_generate (object *op, char *params)
  83. {
  84.       object *tmp;
  85.       int nr = 1, i, retry;
  86.  
  87.   if (!op)
  88.     return 0;
  89.  
  90.   if (params != NULL)
  91.     sscanf(params, "%d", &nr);
  92.       for(i = 0; i < nr; i++) {
  93.         retry = 50;
  94.         while((tmp=generate_treasure(0,op->map->difficulty))==NULL && --retry);
  95.         if (tmp != NULL) {
  96.           tmp = insert_ob_in_ob(tmp, op);
  97.       if (op->type == PLAYER && op->contr->eric_server > 0)
  98.           esrv_send_item (op, tmp);
  99.         }
  100.       }
  101.       return 1;
  102.     }
  103.  
  104. int command_summon (object *op, char *params)
  105. {
  106.       int i;
  107.       object *dummy;
  108.   player *pl;
  109.  
  110.   if (!op)
  111.     return 0;
  112.  
  113.   if(params==NULL) {
  114.          new_draw_info(NDI_UNIQUE, 0,op,"Usage: summon <player>.");
  115.          return 1;
  116.       }
  117.       for(pl=first_player;pl!=NULL;pl=pl->next) 
  118.     if(!strncmp(pl->ob->name, params, MAX_NAME)) 
  119.           break;
  120.       if(pl==NULL) {
  121.         new_draw_info(NDI_UNIQUE, 0,op,"No such player.");
  122.         return 1;
  123.       }
  124.       if(pl->state != ST_PLAYING) {
  125.         new_draw_info(NDI_UNIQUE, 0,op,"That player can't be summoned right now.");
  126.         return 1;
  127.       }
  128.       i=find_free_spot(op->arch,op->map,op->x,op->y,1,8);
  129.       dummy=get_object();
  130.       EXIT_PATH(dummy)=add_string(op->map->path);
  131.       EXIT_X(dummy)=op->x+freearr_x[i];
  132.       EXIT_Y(dummy)=op->y+freearr_y[i];
  133.       enter_exit(pl->ob,dummy);
  134.       free_object(dummy);
  135.       new_draw_info(NDI_UNIQUE, 0,pl->ob,"You are summoned.");
  136.       new_draw_info(NDI_UNIQUE, 0,op,"OK.");
  137.       return 1;
  138.     }
  139.  
  140. int command_create (object *op, char *params)
  141. {
  142.       object *tmp=NULL;
  143.       int nrof,i, magic, set_magic = 0, set_nrof = 0;
  144.       char buf[MAX_BUF], *cp, *bp = buf;
  145.       archetype *at;
  146.       artifact *art=NULL;
  147.  
  148.   if (!op)
  149.     return 0;
  150.  
  151.   if (params == NULL) {
  152.         new_draw_info(NDI_UNIQUE, 0,op, "Usage: create [nr] [magic] <archetype> [ of <artifact>]");
  153.         return 1;
  154.       }
  155.   bp = params;
  156.      
  157.       if(sscanf(bp, "%d ", &nrof)) {
  158.     if ((bp = strchr(params, ' ')) == NULL) {
  159.           new_draw_info(NDI_UNIQUE, 0,op, "Usage: create [nr] [magic] <archetype> [ of <artifact>]");
  160.           return 1;
  161.         }
  162.         bp++;
  163.         set_nrof = 1;
  164.         LOG(llevDebug, "(%d) %s\n", nrof, buf);
  165.       }
  166.       if (sscanf(bp, "%d ", &magic)) {
  167.         if ((bp = strchr(bp, ' ')) == NULL) {
  168.           new_draw_info(NDI_UNIQUE, 0,op, "Usage: create [nr] [magic] <archetype> [ of <artifact>]");
  169.           return 1;
  170.         }
  171.         bp++;
  172.         set_magic = 1;
  173.         LOG(llevDebug, "(%d) (%d) %s\n", nrof, magic, buf);
  174.       }
  175.       if ((cp = strstr(bp, " of ")) != NULL) {
  176.         *cp = '\0';
  177.         cp += 4;
  178.       }
  179.  
  180.       if((at=find_archetype(bp))==NULL) {
  181.         new_draw_info(NDI_UNIQUE, 0,op,"No such archetype.");
  182.         return 1;
  183.       }
  184.  
  185.       if (cp) {
  186.     if (find_artifactlist(at->clone.type)==NULL) {
  187.         new_draw_info_format(NDI_UNIQUE, 0, op,
  188.         "No artifact list for type %d\n", at->clone.type);
  189.     }
  190.     else {
  191.         art = find_artifactlist(at->clone.type)->items;
  192.  
  193.         do {
  194.         if (!strcmp(art->item->name, cp)) break;
  195.         art = art->next;
  196.         } while (art!=NULL);
  197.             if (!art) {
  198.         new_draw_info_format(NDI_UNIQUE, 0, op,
  199.             "No such artifact ([%d] of %s)", at->clone.type, cp);
  200.         }
  201.     }
  202.         LOG(llevDebug, "(%d) (%d) (%s) of (%s)\n",
  203.             set_nrof ? nrof : 0, set_magic ? magic : 0 , bp, cp);
  204.       }
  205.       if(at->clone.nrof) {
  206.         tmp=arch_to_object(at);
  207.         tmp->x=op->x,tmp->y=op->y;
  208.         if (set_nrof)
  209.           tmp->nrof = nrof;
  210.         tmp->map=op->map;
  211.     SET_FLAG(tmp, FLAG_WAS_WIZ);
  212.         if (set_magic)
  213.           set_abs_magic(tmp, magic);
  214.         if (art)
  215.           give_artifact_abilities(tmp, art->item);
  216.         if (need_identify(tmp)) {
  217.       SET_FLAG(tmp, FLAG_IDENTIFIED);
  218.       CLEAR_FLAG(tmp, FLAG_KNOWN_MAGICAL);
  219.     }
  220.         tmp = insert_ob_in_ob(tmp,op);
  221.     if (op->contr->eric_server > 0)
  222.         esrv_send_item(op, tmp);
  223.         return 1;
  224.       } 
  225.       D_LOCK(op);
  226.       for (i=0 ; i < (set_nrof ? nrof : 1); i++) {
  227.         archetype *atmp;
  228.         object *prev=NULL,*head=NULL;
  229.         for (atmp=at;atmp!=NULL;atmp=atmp->more) {
  230.           tmp=arch_to_object(atmp);
  231.       SET_FLAG(tmp, FLAG_WAS_WIZ);
  232.           if(head==NULL)
  233.             head=tmp;
  234.           tmp->x=op->x+tmp->arch->clone.x;
  235.           tmp->y=op->y+tmp->arch->clone.y;
  236.           tmp->map=op->map;
  237.           if (set_magic)
  238.             set_abs_magic(tmp, magic);
  239.           if (art)
  240.             give_artifact_abilities(tmp, art->item);
  241.           if (need_identify(tmp)) {
  242.         SET_FLAG(tmp, FLAG_IDENTIFIED);
  243.         CLEAR_FLAG(tmp, FLAG_KNOWN_MAGICAL);
  244.       }
  245.           if(head!=tmp)
  246.             tmp->head=head,prev->more=tmp;
  247.           prev=tmp;
  248.         }
  249.         if (QUERY_FLAG(head,FLAG_ALIVE))
  250.           insert_ob_in_map(head,op->map);
  251.         else
  252.           head = insert_ob_in_ob(head,op);
  253.         if (at->randomitems!=NULL)
  254.           create_treasure(at->randomitems,head,GT_INVENTORY,
  255.                           op->map->difficulty,0);
  256.     if (op->contr->eric_server > 0) {
  257.         esrv_send_item(op, head);
  258.     }
  259.       }
  260.       D_UNLOCK(op);
  261.       if (op->contr->eric_server <= 0) {
  262.     draw_all_inventory(op);
  263.     draw_all_look(op);
  264.       }
  265.       return 1;
  266. }
  267.  
  268. /* if(<not socket>) */
  269.  
  270. /*
  271.  * Now follows dm-commands which are also acceptable from sockets
  272.  */
  273.  
  274. int command_inventory (object *op, char *params)
  275. {
  276.     object *tmp;
  277.     int i;
  278.  
  279.   if (!params) {
  280.     inventory(op, NULL);
  281.     return 0;
  282.   }
  283.  
  284.   if(!sscanf(params, "%d", &i) || (tmp=find_object(i))==NULL) {
  285.       new_draw_info(NDI_UNIQUE, 0,op,"Inventory of what object (nr)?");
  286.       return 1;
  287.     }
  288.     inventory(op,tmp);
  289.     return 1;
  290.   }
  291.  
  292. /* just show player's their skills for now. Dm's can
  293.  * already see skills w/ inventory command - b.t.
  294.  */
  295.  
  296. int command_skills (object *op, char *params)
  297. {
  298.      show_skills(op);
  299.      return 0;
  300. }
  301.  
  302. int command_dump (object *op, char *params)
  303. {
  304.     int i;
  305.   object *tmp;
  306.  
  307.   if(params!=NULL && !strcmp(params, "me"))
  308.       tmp=op;
  309.   else if(params==NULL || !sscanf(params, "%d", &i) ||
  310.       (tmp=find_object(i))==NULL) {
  311.       new_draw_info(NDI_UNIQUE, 0,op,"Dump what object (nr)?");
  312.       return 1;
  313.     }
  314.     dump_object(tmp);
  315.     new_draw_info(NDI_UNIQUE, 0,op,errmsg);
  316.     return 1;
  317.   }
  318.  
  319. int command_patch (object *op, char *params)
  320. {
  321.     int i;
  322.     char *arg,*arg2;
  323.     char buf[MAX_BUF];
  324.   object *tmp;
  325.  
  326.     tmp=NULL;
  327.   if(params != NULL) {
  328.     if(!strncmp(params, "me", 2))
  329.         tmp=op;
  330.     else if(sscanf(params, "%d", &i))
  331.         tmp=find_object(i);
  332.     else if(sscanf(params, "%s", buf))
  333.         tmp=find_object_name(buf);
  334.     }
  335.     if(tmp==NULL) {
  336.       new_draw_info(NDI_UNIQUE, 0,op,"Patch what object (nr)?");
  337.       return 1;
  338.     }
  339.   arg=strchr(params, ' ');
  340.     if(arg==NULL) {
  341.       new_draw_info(NDI_UNIQUE, 0,op,"Patch what values?");
  342.       return 1;
  343.     }
  344.     if((arg2=strchr(++arg,' ')))
  345.       arg2++;
  346.     SET_FLAG(tmp, FLAG_WAS_WIZ); /* To avoid cheating */
  347.     if(set_variable(tmp,arg) == -1)
  348.       new_draw_info(NDI_UNIQUE, 0,op,errmsg);
  349.     else {
  350.       new_draw_info_format(NDI_UNIQUE, 0, op,
  351.     "(%s#%d)->%s=%s",tmp->name,tmp->count,arg,arg2);
  352.     }
  353.     return 1;
  354.   }
  355.  
  356. int command_remove (object *op, char *params)
  357. {
  358.     int i;
  359.   object *tmp;
  360.  
  361.   if(params==NULL || !sscanf(params, "%d", &i) || (tmp=find_object(i))==NULL) {
  362.       new_draw_info(NDI_UNIQUE, 0,op,"Remove what object (nr)?");
  363.       return 1;
  364.     }
  365.     remove_ob(tmp);
  366.     return 1;
  367.   }
  368.  
  369. int command_free (object *op, char *params)
  370. {
  371.     int i;
  372.   object *tmp;
  373.  
  374.   if(params==NULL || !sscanf(params, "%d", &i) || (tmp=find_object(i))==NULL) {
  375.       new_draw_info(NDI_UNIQUE, 0,op,"Free what object (nr)?");
  376.       return 1;
  377.     }
  378.     free_object(tmp);
  379.     return 1;
  380.   }
  381.  
  382. int command_addexp (object *op, char *params)
  383. {
  384.     char buf[MAX_BUF];
  385.     int i;
  386. #ifdef ALLOW_SKILLS
  387.   object *exp_ob,*skill;
  388. #endif
  389.   player *pl;
  390.  
  391.   if(params==NULL || sscanf(params, "%s %d", buf, &i)!=2) {
  392.        new_draw_info(NDI_UNIQUE, 0,op,"Usage: addexp [who] [how much].");
  393.        return 1;
  394.     }
  395.     for(pl=first_player;pl!=NULL;pl=pl->next) 
  396.       if(!strncmp(pl->ob->name,buf,MAX_NAME)) 
  397.         break;
  398.     if(pl==NULL) {
  399.       new_draw_info(NDI_UNIQUE, 0,op,"No such player.");
  400.       return 1;
  401.     }
  402.  
  403. /* In new system: for dm adding experience to a player, only can 
  404.  * add exp if we satisfy the following: 
  405.  * 1) there is an associated skill readied by the player 
  406.  * 2) added exp doesnt result in exp_ob->stats.exp>MAX_EXP_IN_OBJ 
  407.  */
  408.  
  409. #ifdef ALLOW_SKILLS
  410.     if((skill = pl->ob->chosen_skill) && ((exp_ob = pl->ob->chosen_skill->exp_obj)
  411.        || link_player_skill(pl->ob, skill))) { 
  412.       i = check_dm_add_exp_to_obj(exp_ob,i);
  413.       exp_ob->stats.exp += i;
  414.     } else {
  415.       new_draw_info(NDI_UNIQUE, 0,op,"Can't find needed experience object.");
  416.       new_draw_info(NDI_UNIQUE, 0,op,"Player has no associated skill readied.");
  417.       return 1;
  418.     }
  419. #endif
  420.     pl->ob->stats.exp += i;
  421.     add_exp(pl->ob,0);
  422.     SET_FLAG(pl->ob, FLAG_WAS_WIZ);
  423.     draw_stats(pl->ob);
  424.     return 1;
  425.   }
  426.  
  427. int command_speed (object *op, char *params)
  428. {
  429.     int i;
  430.   if(params==NULL || !sscanf(params, "%d", &i)) {
  431.       sprintf(errmsg,"Current speed is %ld",max_time);
  432.       new_draw_info(NDI_UNIQUE, 0,op,errmsg);
  433.       return 1;
  434.     }
  435.     set_max_time(i);
  436.     reset_sleep();
  437.     new_draw_info(NDI_UNIQUE, 0,op,"The speed is changed.");
  438.     return 1;
  439.   }
  440.  
  441.  
  442. /**************************************************************************/
  443. /* Mods made by Tyler Van Gorder, May 10-13, 1992.                        */
  444. /* CSUChico : tvangod@cscihp.ecst.csuchico.edu                            */
  445. /**************************************************************************/
  446.  
  447. int command_stats (object *op, char *params)
  448. {
  449.   char thing[20];
  450.   player *pl;
  451.   char buf[MAX_BUF];
  452.  
  453.     thing[0] = '\0';
  454.   if(params==NULL || !sscanf(params, "%s", thing) || thing == NULL) {
  455.        new_draw_info(NDI_UNIQUE, 0,op,"Who?");
  456.        return 1;
  457.     }
  458.     for(pl=first_player;pl!=NULL;pl=pl->next) 
  459.        if(!strcmp(pl->ob->name,thing)) {
  460.          sprintf(buf,"Str : %-2d      H.P. : %-4d  MAX : %d",
  461.                  pl->ob->stats.Str,pl->ob->stats.hp,pl->ob->stats.maxhp);
  462.          new_draw_info(NDI_UNIQUE, 0,op,buf);
  463.          sprintf(buf,"Dex : %-2d      S.P. : %-4d  MAX : %d",
  464.                  pl->ob->stats.Dex,pl->ob->stats.sp,pl->ob->stats.maxsp) ;
  465.          new_draw_info(NDI_UNIQUE, 0,op,buf);
  466.          sprintf(buf,"Con : %-2d        AC : %-4d  WC  : %d",
  467.                  pl->ob->stats.Con,pl->ob->stats.ac,pl->ob->stats.wc) ;
  468.          new_draw_info(NDI_UNIQUE, 0,op,buf);
  469.          sprintf(buf,"Wis : %-2d       EXP : %d",
  470.                  pl->ob->stats.Wis,pl->ob->stats.exp);
  471.          new_draw_info(NDI_UNIQUE, 0,op,buf);
  472.          sprintf(buf,"Cha : %-2d      Food : %d",
  473.                  pl->ob->stats.Cha,pl->ob->stats.food) ;
  474.          new_draw_info(NDI_UNIQUE, 0,op,buf);
  475.          sprintf(buf,"Int : %-2d    Damage : %d",
  476.                  pl->ob->stats.Int,pl->ob->stats.dam) ;
  477.          sprintf(buf,"Pow : %-2d    Grace : %d",
  478.                  pl->ob->stats.Pow,pl->ob->stats.grace) ;
  479.          new_draw_info(NDI_UNIQUE, 0,op,buf);
  480.          break;
  481.        }
  482.     if(pl==NULL)
  483.        new_draw_info(NDI_UNIQUE, 0,op,"No such player.");
  484.     return 1;
  485.   }
  486.  
  487. int command_abil (object *op, char *params)
  488. {
  489.   char thing[20], thing2[20];
  490.   int iii;
  491.   player *pl;
  492.   char buf[MAX_BUF];
  493.  
  494.     iii = 0;
  495.     thing[0] = '\0';
  496.     thing2[0] = '\0';
  497.   if(params==NULL || !sscanf(params, "%s %s %d", thing, thing2, &iii) ||
  498.      thing==NULL) {
  499.        new_draw_info(NDI_UNIQUE, 0,op,"Who?");
  500.        return 1;
  501.     }
  502.     if (thing2==NULL){
  503.        new_draw_info(NDI_UNIQUE, 0,op,"You can't change that.");
  504.        return 1;
  505.     }
  506.     if (iii<MIN_STAT||iii>MAX_STAT) {
  507.       new_draw_info(NDI_UNIQUE, 0,op,"Illegal range of stat.\n");
  508.       return 1;
  509.     }
  510.     for(pl=first_player;pl!=NULL;pl=pl->next) 
  511.        if(!strcmp(pl->ob->name,thing)){   
  512.       SET_FLAG(pl->ob, FLAG_WAS_WIZ);
  513.           if(!strcmp("str",thing2))
  514.             pl->ob->stats.Str = iii,pl->orig_stats.Str = iii;
  515.           if(!strcmp("dex",thing2))   
  516.             pl->ob->stats.Dex = iii,pl->orig_stats.Dex = iii;
  517.           if(!strcmp("con",thing2))
  518.             pl->ob->stats.Con = iii,pl->orig_stats.Con = iii;
  519.           if(!strcmp("wis",thing2))
  520.             pl->ob->stats.Wis = iii,pl->orig_stats.Wis = iii;
  521.           if(!strcmp("cha",thing2))
  522.             pl->ob->stats.Cha = iii,pl->orig_stats.Cha = iii;
  523.           if(!strcmp("int",thing2))
  524.             pl->ob->stats.Int = iii,pl->orig_stats.Int = iii;
  525.           if(!strcmp("pow",thing2))
  526.             pl->ob->stats.Pow = iii,pl->orig_stats.Pow = iii;
  527.           sprintf(buf,"%s has been altered.",pl->ob->name);
  528.           new_draw_info(NDI_UNIQUE, 0,op,buf);
  529.           fix_player(pl->ob);
  530.          return 1;
  531.        } 
  532.     new_draw_info(NDI_UNIQUE, 0,op,"No such player.");
  533.     return 1;
  534.   }
  535.  
  536. int command_reset (object *op, char *params)
  537. {
  538.     mapstruct *m;
  539.     object *dummy = NULL, *tmp = NULL;
  540.  
  541.   if (params == NULL) {
  542.       new_draw_info(NDI_UNIQUE, 0,op,"Reset what map [name]?");
  543.       return 1;    
  544.     }
  545.   if (strcmp(params, ".") == 0)
  546.     params = op->map->path;
  547.   m = has_been_loaded(params);
  548.     if (m==NULL) {
  549.       new_draw_info(NDI_UNIQUE, 0,op,"No such map.");
  550.       return 1;    
  551.     }
  552.  
  553.     if (m->in_memory != MAP_SWAPPED) {
  554.       player *pl;
  555.  
  556.     if(m->in_memory != MAP_IN_MEMORY) {
  557.         LOG(llevError,"Tried to swap out map which was not in memory.\n");
  558.         return 0;
  559.     }
  560.     for(pl=first_player;pl!=NULL;pl=pl->next)
  561.         if(pl->ob == NULL || (!(QUERY_FLAG(pl->ob,FLAG_REMOVED)) && pl->ob->map == m))
  562.         if (QUERY_FLAG(pl->ob,FLAG_WIZ)) {
  563.             /* does not work if there are several dms in same map */
  564.             tmp = pl->ob;
  565.             dummy=get_object();
  566.             dummy->map = m;
  567.             EXIT_X(dummy) = tmp->x;
  568.             EXIT_Y(dummy) = tmp->y;
  569.       EXIT_PATH(dummy) = add_string (params);
  570.             remove_ob (tmp);
  571.         } else
  572.             break;
  573.     swap_map(m);
  574.       }
  575.  
  576.       if (m->in_memory == MAP_SWAPPED) {    
  577.     LOG(llevDebug,"Resetting map %s.\n",m->path);
  578.     clean_tmp_map(m);
  579.     if (m->tmpname) free(m->tmpname);
  580.     m->tmpname = NULL;
  581.     m->reset_time = 0;
  582.     
  583.     if (tmp) {
  584.         enter_exit(tmp, dummy);
  585.         /* sigh - enter exit does not insert object 
  586.            if it is removed */
  587.         SET_FLAG(tmp, FLAG_NO_APPLY);
  588.         insert_ob_in_map(tmp,tmp->map);
  589.         CLEAR_FLAG(tmp, FLAG_NO_APPLY);
  590.         free_object(dummy);
  591.     }
  592.  
  593.       new_draw_info(NDI_UNIQUE, 0,op,"OK.");
  594.       return 1;          
  595.     }
  596.     new_draw_info(NDI_UNIQUE, 0,op,"Reset failed, couldn't swap map.\n");
  597.     return 1;
  598.   }
  599.  
  600. int command_nowiz (object *op, char *params) /* 'noadm' is alias */
  601. {
  602.      if(op == NULL) {
  603.        active_socket->wiz = 0;
  604.        return 1;
  605.      }
  606.      CLEAR_FLAG(op, FLAG_WIZ);
  607.      CLEAR_FLAG(op, FLAG_WIZPASS);
  608.      CLEAR_FLAG(op, FLAG_FLYING);
  609.      return 1;
  610.   }
  611.  
  612.  
  613. static int checkdm(object *op, char *pl_name, char *pl_passwd, char *pl_host)
  614. {
  615.   FILE  *dmfile;
  616.   char  buf[MAX_BUF];
  617.   char  line_buf[160], name[160], passwd[160], host[160];
  618.  
  619.   sprintf (buf, "%s/%s", LIBDIR, DMFILE);
  620.   if ((dmfile = fopen(buf, "r")) == NULL) {
  621.     LOG (llevDebug, "Could not find DM file.\n");
  622.     return(0);
  623.   }
  624.   while(fgets(line_buf, 160, dmfile) != NULL) {
  625.     if (line_buf[0]=='#') continue;
  626.     if (sscanf(line_buf,"%[^:]:%[^:]:%s\n",name, passwd, host)!=3) {
  627.     LOG(llevError,"Warning - malformed dm file entry: %s", line_buf);
  628.     }
  629.     else if ((!strcmp(name,"*") || (pl_name && !strcmp(pl_name, name)))
  630.       && (!strcmp(passwd,"*") || !strcmp(passwd,pl_passwd)) &&
  631.       (!strcmp(host,"*") || !strcmp(host, pl_host))) {
  632.     fclose(dmfile);
  633.     return (1);
  634.     }
  635.   }
  636.   fclose(dmfile);
  637.   return (0);
  638. }
  639.  
  640. /* Actual command to perhaps become dm.  Changed aroun a bit in version 0.92.2
  641.  * - allow people on sockets to become dm, and allow better dm file
  642.  */
  643.  
  644. int command_dm (object *op, char *params)
  645. {
  646.   if (op==NULL) {
  647.     if (checkdm(op, active_socket->name, params?params:"*", active_socket->host)) {
  648.       active_socket->wiz=1;
  649.       new_draw_info(NDI_UNIQUE, 0,op, "Ok, you are the Dungeon Master!");
  650.       new_draw_info(NDI_UNIQUE | NDI_ALL, 1, NULL,
  651.     "The Dungeon Master has arrived!");
  652.     }
  653.     else {
  654.       new_draw_info(NDI_UNIQUE, 0,op, "Sorry Pal, I don't think so.");
  655.       LOG(llevDebug,"socket[%s]: DM mode attempted (%s %s)\n", 
  656.       active_socket->name,params?params:"*", active_socket->host);
  657.     }
  658.     return 1;
  659.   }
  660.   /* If this isn't a player, quit out now */
  661.   else if (!op->contr) return 0;
  662.   else {
  663.     char *s1, player_host[160];
  664.     /* op->contr->name is actually the displayname */
  665.     if (op->contr->name) {
  666.     strcpy(player_host, op->contr->name);
  667.     /* Next line removes the :0 or :0.0 from the player hostname, if it
  668.      * is there
  669.      */
  670.     if ((s1=strchr(player_host, ':'))!=NULL) *s1='\0';
  671.     }
  672.     else strcpy(player_host,"*");
  673.     /* op->contr->username is the name supplied with the name command via
  674.      * the socket
  675.      */
  676.     if (checkdm(op, (op->contr->username?op->contr->username:"*"), 
  677.         (params?params:"*"), player_host)) {
  678.       SET_FLAG(op, FLAG_WIZ);
  679.       SET_FLAG(op, FLAG_WAS_WIZ);
  680.       SET_FLAG(op, FLAG_WIZPASS);
  681.       new_draw_info(NDI_UNIQUE, 0,op, "Ok, you are the Dungeon Master!");
  682.       new_draw_info(NDI_UNIQUE | NDI_ALL, 1, NULL,
  683.       "The Dungeon Master has arrived!");
  684.       SET_FLAG(op, FLAG_FLYING);
  685.       clear_los(op);
  686.       op->contr->writing =0;
  687.       op->contr->write_buf[0] ='\0';
  688.       return 1;
  689.     } else {
  690.       new_draw_info(NDI_UNIQUE, 0,op, "Sorry Pal, I don't think so.");
  691.       op->contr->writing =0;
  692.       op->contr->write_buf[0] ='\0';
  693.       return 1;
  694.     }
  695.   }
  696. }
  697.  
  698.